package com.example.mobile2021606127cxz0427;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class ItemsAdapter extends RecyclerView.Adapter<ItemsAdapter.MyViewHolder> {
    private List<Items> list;

    public ItemsAdapter(List<Items> list) {
        this.list = list;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Items items = list.get(position);
        holder.image.setImageResource(items.getImage());
        holder.text1.setText(items.getText1());
        holder.text2.setText(items.getText2());
        holder.text3.setText(items.getText3());
        holder.text4.setText(items.getText4());
        holder.text5.setText(items.getText5());
        holder.text6.setText(items.getText6());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView image;
        TextView text1, text2, text3, text4, text5, text6;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.iv);
            text1 = itemView.findViewById(R.id.tv1);
            text2 = itemView.findViewById(R.id.tv2);
            text3 = itemView.findViewById(R.id.tv3);
            text4 = itemView.findViewById(R.id.tv4);
            text5 = itemView.findViewById(R.id.tv5);
            text6 = itemView.findViewById(R.id.tv6);
        }
    }
}
